#ifndef AD9910_CTRL_H
#define AD9910_CTRL_H

#include <QObject>
#include <QTcpServer>
#include <QTcpSocket>

enum class TCP_FRAME_HEAD : uint8_t
{
    Single = 0x00,
    First = 0x01,
    Middle = 0x02,
    Last = 0x03
};

enum class CMD_HEAD : uint8_t
{
    SetProfile = 0x01,
    SetRamData = 0x02,
    SetEnable = 0x03,
    SetUpdate = 0x04,
    SetRamDemo = 0x05,
    readRamData = 0x06,
    SetTimer = 0x07
};

enum class RAM_MODE : uint8_t
{
    DirtSwitch = 0b000,  // 直接转换模式
    RampUp = 0b001,      // 上斜坡模式
    BidRamp = 0b010,     // 双向斜坡模式
    ContBidRamp = 0b011, // 连续双向斜坡模式
    ContReCirc = 0b100   // 连续循环模式
};

class AD9910_CTRL : public QObject
{
    Q_OBJECT
public:
    explicit AD9910_CTRL(QObject *parent = nullptr);

    void connectTcpServer();

    QByteArray genByteArr_Profile(const uint16_t addrStepRate, RAM_MODE mode);
    QByteArray genByteArr_Enable(bool enable);
    QByteArray genByteArr_Update();
    QByteArray genByteArr_SetTimer(bool enable, const uint32_t sec, const uint32_t usec);
    QVector<uint16_t> genRamData(const QMap<int, int> points);

    bool sendSingleData(const QByteArray &data);
    bool sendRamData(const QVector<uint16_t> &data);

    QTcpSocket *tcpClient;

signals:
};

#endif // AD9910_CTRL_H
